package com.juneng.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.juneng.common.R;
import com.juneng.utils.Func;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import com.juneng.entity.CourseLog;
import com.juneng.dto.CourseLogDto;
import com.juneng.dto.CourseLogQueryDto;
import com.juneng.vo.CourseLogVo;
import com.juneng.service.ICourseLogService;

import java.util.List;

/**
 * 课程观看记录表 控制器
 *
 * @author zds
 * @since 2021-07-08
 */
@RestController
@AllArgsConstructor
@RequestMapping("courseLog")
@Api(tags = "课程观看记录表相关接口")
public class CourseLogController {

	private ICourseLogService courseLogService;

	/**
	 * 详情
	 */
	@GetMapping("/detail")
	@ApiOperation(value = "详情", notes = "传入id")
	public R<CourseLog> detail(Integer id) {
		CourseLog detail = courseLogService.getById(id);
		return R.success(detail);
	}

	/**
	 * 分页 课程观看记录表
	 */
	@GetMapping("/page")
	@ApiOperation(value = "分页", notes = "传入courseLog")
	public R<IPage<CourseLogVo>> page(CourseLogQueryDto dto) {
		IPage<CourseLogVo> pages = courseLogService.page(dto);
		return R.success(pages);
	}
	/**
	 * 列表 课程观看记录表
	 */
	@GetMapping("/list")
	@ApiOperation(value = "不分页", notes = "传入courseLog")
	public R<List<CourseLog>> list(CourseLogQueryDto dto) {
		List<CourseLog> list = courseLogService.list(dto);
		return R.success(list);
	}

	/**
	 * 新增 课程观看记录表
	 */
	@PostMapping("/save")
	@ApiOperation(value = "新增", notes = "传入courseLog")
	public R save(@RequestBody CourseLogDto dto) {
		return R.success(courseLogService.save(dto));
	}

	/**
	 * 修改 课程观看记录表
	 */
	@PutMapping("/update")
	@ApiOperation(value = "修改", notes = "传入courseLog")
	public R update(@RequestBody CourseLogDto dto) {
		return R.success(courseLogService.updateById(dto));
	}

	/**
	 * 删除 课程观看记录表
	 */
	@DeleteMapping("/remove")
	@ApiOperation(value = "逻辑删除", notes = "传入ids")
	public R remove(@ApiParam(value = "主键集合", required = true) @RequestParam String ids) {
		return R.success(courseLogService.deleteLogic(Func.toIntList(ids)));
	}
}
